package health.lm.com.shop.model;


import org.json.JSONArray;
import org.json.JSONObject;

import java.util.List;

import health.lm.com.data.App;
import health.lm.com.data.HttpCST;
import health.lm.com.network.EasyHttp;
import health.lm.com.network.callback.SimpleCallBack;
import health.lm.com.network.utils.MyApi;
import health.lm.com.shop.entity.BusinessListEntity;
import health.lm.com.shop.entity.CompanyDynamicResponse;
import health.lm.com.shop.entity.DynamicCategoryEntity;
import health.lm.com.shop.entity.EvaluationEntity;
import health.lm.com.shop.entity.HLChatResponse;
import health.lm.com.shop.entity.HLCompanyLeaderResponse;
import health.lm.com.shop.entity.HLPeopleDetailResponse;
import health.lm.com.shop.entity.HLPrivateMessageResponse;
import health.lm.com.shop.entity.MemberListResponse;
import health.lm.com.shop.entity.MyCompanyResponse;
import health.lm.com.shop.entity.OrganizationEntity;
import health.lm.com.shop.entity.PeopleChainEntity;
import health.lm.com.shop.entity.PeopleDiscoverEntity;


/**
 * Created by Android Studio .
 * 作者：zhong
 * 日期：2018/12/2
 * 邮箱：15206394364@163.com
 * 介绍：Mall 模块 DAO
 * 修订：====================
 */
public class MallModel {
    private static MallModel mallModel;

    public static MallModel getInstance() {
        if (null == mallModel) mallModel = new MallModel();
        return mallModel;
    }

    /**
     * 获取人脉连首页数据
     *
     * @param pCallBack 回调
     */
    public void getPeopleChainData(SimpleCallBack<PeopleChainEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CONNECTION, HttpCST.INTFC_1001, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 获取人脉连首页数据
     *
     * @param pCallBack 回调
     */
    public void getPeopleDiscoverData(SimpleCallBack<PeopleDiscoverEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CONNECTION, HttpCST.INTFC_1006, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 首页 下部分 资讯新闻列表
     *
     * @param id        分类id(非必须选
     * @param page      第几页
     * @param pageSize  每页几个
     * @param pCallBack 回调
     */
    public void getHomeNewsData(String id, int page, int pageSize, SimpleCallBack<CompanyDynamicResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, pageSize);
            jsonObject.put("category_id", id);
            jsonObject.put("bussiness_id", "0");
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1010, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 商会列表顶部 分类标签
     *
     * @param pCallBack 回调
     */
    public void getDynamicCategoryData(SimpleCallBack<DynamicCategoryEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1010, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 商会列表
     *
     * @param pCallBack 回调
     */
    public void getBusinessListData(int page, int pageSize, SimpleCallBack<BusinessListEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, pageSize);
            jsonObject.put("type", 2);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1005, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 影响力中心列表
     *
     * @param pCallBack 回调
     */
    public void getInfluenceCenterData(int page, int pageSize, SimpleCallBack<BusinessListEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, pageSize);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1009, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 关注接口
     *
     * @param id   被关注id（多个id一键关注,id数组）
     * @param type 关注类型（1：关注会员，2：关注商会）
     */
    public void attention(List<String> id, int type, SimpleCallBack<Object> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        JSONArray jsonArray = new JSONArray();
        for (String follow_id : id) jsonArray.put(follow_id);
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("follow_id", jsonArray);
            jsonObject.put(HttpCST.TYPE, type);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CONNECTION, HttpCST.INTFC_1005, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 我的商会信息
     *
     * @param bussiness_id 商会ID
     * @param pCallBack    回调
     */
    public void myBusinessData(String bussiness_id, SimpleCallBack<MyCompanyResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("bussiness_id", bussiness_id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1001, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 商会领导列表
     *
     * @param bussiness_id 商会ID
     * @param pCallBack    回调
     */
    public void getLeaderData(String bussiness_id, SimpleCallBack<HLCompanyLeaderResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("bussiness_id", bussiness_id);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1002, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 商会会员列表
     *
     * @param bussiness_id 商会ID
     * @param page         页数
     * @param page_size    每页个数
     * @param sername      搜索名称
     * @param pCallBack    回调
     */
    public void getMemberListData(String bussiness_id, int page, int page_size, String sername, SimpleCallBack<MemberListResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, page_size);
            jsonObject.put("bussiness_id", bussiness_id);
            jsonObject.put("sername", sername);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1003, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * ___Bussiness_ - 【1004】会员详情
     *
     * @param uid       用户id
     * @param pCallBack 回调
     */
    public void getMemberDetailData(String uid, SimpleCallBack<HLPeopleDetailResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("uid", uid);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1004, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 我的人脉
     *
     * @param page      页数
     * @param page_size 每页个数
     * @param sername
     * @param pCallBack
     */
    public void getMyPeopleChainData(int page, int page_size, String sername, SimpleCallBack<MemberListResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, page_size);
            jsonObject.put("sername", sername);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CONNECTION, HttpCST.INTFC_1007, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 影响力团队
     *
     * @param page      页数
     * @param page_size 每页个数
     * @param sername
     * @param pCallBack
     */
    public void getInfluenceTeamData(int page, int page_size, String sername, SimpleCallBack<MemberListResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, page_size);
            jsonObject.put("sername", sername);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_MEMBER, HttpCST.INTFC_1015, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 私信列表
     *
     * @param page      页数
     * @param page_size 每页个数
     * @param pCallBack 回调
     */
    public void getPrivateChatList(int page, int page_size, SimpleCallBack<HLPrivateMessageResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, page_size);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CHAT, HttpCST.INTFC_1001, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * ___Chat_ - 【1002】进行对话
     *
     * @param getid     对话对方会员ID
     * @param pCallBack 回调
     */
    public void getChatingList(String getid, SimpleCallBack<HLChatResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("getid", getid);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CHAT, HttpCST.INTFC_1002, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * ___Chat_ - 【1003】提交对话
     *
     * @param getid     对话对方会员ID
     * @param content   对话内容
     * @param pCallBack 回调
     */
    public void getChatSubmit(String getid, String content, SimpleCallBack<Object> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("getid", getid);
            jsonObject.put("content", content);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CHAT, HttpCST.INTFC_1003, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * ___Chat_ - 【1005】历史对话
     *
     * @param getid     对话对方会员ID
     * @param pCallBack 回调
     */
    public void getChatHistory(String getid, int page, int page_size, SimpleCallBack<HLChatResponse> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, page_size);
            jsonObject.put("getid", getid);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_CHAT, HttpCST.INTFC_1005, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 获取组织架构数据
     *
     * @param getid     商会Id
     * @param pCallBack 回调
     */
    public void getOrganizationData(String getid, SimpleCallBack<List<OrganizationEntity>> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put("bussiness_id", getid);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_BUSSINESS, HttpCST.INTFC_1011, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
    }

    /**
     * 商品详情页评论列表
     *
     * @param pCallBack pCallBack
     */
    public void productDetailEva(String id, int page, int pageSize, SimpleCallBack<EvaluationEntity> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST._id, id);
            jsonObject.put(HttpCST.PAGE, page);
            jsonObject.put(HttpCST.PAGE_SIZE, pageSize);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_SHOP, HttpCST.INTFC_1011, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
//        OkGoBuilder.getInstance().cls(BaseResponse.class).json(json).callback(observer).build();
    }

    /**
     * 收藏
     *
     * @param pCallBack pCallBack
     */
    public void productCollection(String id, String is_collection, SimpleCallBack<Object> pCallBack) {
        JSONObject jsonObject = new JSONObject();
        String json = "";
        try {
            jsonObject.put(HttpCST.ACCESS_TOKEN, App.getModel().getAccess_token());
            jsonObject.put(HttpCST._id, id);
            jsonObject.put("is_collection", is_collection);
            json = MyApi.getInstance().generateMessage(HttpCST.MODULE_SHOP, HttpCST.INTFC_1020, jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }
        EasyHttp.post("/").upJson(json).execute(pCallBack);
//        OkGoBuilder.getInstance().cls(BaseResponse.class).json(json).callback(observer).build();
    }
}
